package com.app.web.user.team;

import com.app.utils.base.http.ResultUtil;
import com.app.utils.base.j2se.Common;
import com.app.utils.base.j2se.Convert;
import com.app.utils.base.j2se.DateUtil;
import com.app.utils.base.j2se.Logger;
import com.app.utils.base.page.Pages;
import com.app.utils.spring.properties.Config;
import com.app.web.user.info.UserInfo;
import com.app.web.user.info.UserInfoService;
import com.app.web.user.login.LoginInfo;
import com.app.web.user.login.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description 团队服务控制器 负责对外提供团队服务
 * @author liuyang
 * @date 2019-05-05
 */
@RestController
@RequestMapping("/user/team/")
public class TeamController {
    @Autowired
    private UserInfoService userInfoModel;
    @Autowired
    private TeamService teamModel;
    /**
     * 功能：获取团队信息
     * @param uid 登录用户id
     * @return
     */
    @RequestMapping("search")
//    @RedisCache(timeOut = 5)
    public String info(@RequestAttribute int uid, @RequestParam String nickName, int pageNum){
        UserInfo userInfo = userInfoModel.info(uid);
        if(userInfo.getRole()<=0){
            ResultUtil.error("6001", Config.pp.get("6001"));
        }
        //下级和直属下级人数
        List<Map<String,Object>> data = teamModel.getSubAndNextList(userInfo.getMcode(),nickName,pageNum);
        if(Common.isEmpty(data)){
            return ResultUtil.error(555,"暂无数据");
        }
        return ResultUtil.success(data);
    }
}
